package com.kh.pajx.sop.dao.bal.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.kh.pajx.sop.base.BaseDaoImpl;
import com.kh.pajx.sop.dao.bal.IBalBuMgrDriveDao;
import com.kh.pajx.sop.domain.bal.BalBuMgrDrive;

/**
 * 行业经理季度结算 数据库持久化操作实现类
 * @author:	azzcsimp
 * @Createdate:	2015年1月27日 下午3:40:29
 */
@SuppressWarnings("unchecked")
@Repository
public class BalBuMgrDriveDaoImpl extends BaseDaoImpl<BalBuMgrDrive> implements IBalBuMgrDriveDao {

	@Override
	public List<BalBuMgrDrive> findList(int state) throws Exception{
		return getSession().createQuery(//
				"FROM BalBuMgrDrive bal WHERE bal.billState=?") //
				.setParameter(0, state) //
				.list(); //
	}
	
	@Override
	public List<BalBuMgrDrive> findList(String billCode, int billState) throws Exception{
		return getSession().createQuery(//
				"FROM BalBuMgrDrive bal WHERE bal.billCode=? AND bal.billState=?") //
				.setParameter(0, billCode) //
				.setParameter(1, billState)
				.list(); //
	}
	
	@Override
	public BalBuMgrDrive getByCode(String billCode) throws Exception {
		return (BalBuMgrDrive)getSession().createQuery(//
				"FROM BalBuMgrDrive bal WHERE bal.billCode=?")
				.setParameter(0, billCode) //
				.uniqueResult();
	}
	
	@Override
	public List<BalBuMgrDrive> findByBillCodeList(List<String> bumgrBills) throws Exception {
		return getSession().createQuery(//
				"FROM BalBuMgrDrive bal WHERE bal.billState=3 AND bal.billCode IN (:billcodeList)") //
				.setParameterList("billcodeList", bumgrBills)//
				.list();
	}
	
	@Override
	public List<BalBuMgrDrive> findByBillCodeList(List<String> bumgrBills, String areaCode) throws Exception {
		return getSession().createQuery(//
				"FROM BalBuMgrDrive bal WHERE bal.areaCode=? AND bal.billState=3 AND bal.billCode IN (:billcodeList)") //
				.setParameter(0, areaCode)
				.setParameterList("billcodeList", bumgrBills)//
				.list();
	}
	
	@Override
	public List<BalBuMgrDrive> findByBillCodeList(List<String> bumgrBills, String areaCode, String deptCode) throws Exception {
		return getSession().createQuery(//
				"FROM BalBuMgrDrive bal WHERE bal.saleDeptId=? AND bal.billState=3 AND bal.billCode IN (:billcodeList)") //
				.setParameter(0, deptCode) //
				.setParameterList("billcodeList", bumgrBills)//
				.list();
	}
	
}
